package com.example.teamtribe.main.club.join;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.example.teamtribe.common.Back;
import com.example.teamtribe.common.model.RelationModel;
import com.example.teamtribe.json.JsonTeamRequestReason;
import com.example.teamtribe.utils.Utility;
import com.google.gson.Gson;

public class ApplyPresenter implements ApplyContract.Presenter {

    private ApplyContract.View view;

    public ApplyPresenter(ApplyContract.View view) {
        this.view = view;
    }

    @Override
    public void send(int teamId, String phone, String qq) {
        view.showProgress();
        String reason = new Gson().toJson(new JsonTeamRequestReason(Utility.getUser(), phone, qq));
        RelationModel.getInstance().request(1, Utility.getToken(), teamId, reason, new Back() {
            @Override
            public void success(@Nullable Bundle bundle) {
                view.next();
            }

            @Override
            public void failure(String meg) {
                view.hideProgress();
                view.showToast(meg);
            }
        });
    }
}
